home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / language / asxsrc.arc / M05MCH.C < prev    next >
C/C++ Source or Header  |  1989-08-25  |  4KB  |  271 lines

  1. /* m05mch.c */
  2.  
  3. /*
  4.  * (C) Copyright 1989
  5.  * All Rights Reserved
  6.  *
  7.  * Alan R. Baldwin
  8.  * 721 Berkeley St.
  9.  * Kent, Ohio  44240
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <setjmp.h>
  14. #include "asm.h"
  15. #include "6805.h"
  16.  
  17. #define    NB    256
  18.  
  19. int    *bp;
  20. int    bm;
  21. int    bb[NB];
  22.  
  23. struct    sdp    sdp[] = {
  24.     NULL
  25. };
  26.  
  27. /*
  28.  * Process a machine op.
  29.  */
  30. VOID
  31. machine(mp)
  32. struct mne *mp;
  33. {
  34.     register op, t1, t2, type;
  35.     struct expr e1, e2, e3;
  36.     addr_t espv;
  37.     struct area *espa;
  38.     char id[NCPS];
  39.     int flag, v1;
  40.  
  41.     op = mp->m_valu;
  42.     type = mp->m_type;
  43.     switch (type) {
  44.  
  45.     case S_SDP:
  46.         espa = NULL;
  47.         if (more()) {
  48.             getid(id, -1);
  49.             espa = alookup(id);
  50.             if ( espa == NULL) {
  51.                 err('u');
  52.             }
  53.         }
  54.         if (espa) {
  55.             sdp->s_area = espa;
  56.         } else {
  57.             sdp->s_area = dot->s_area;
  58.         }
  59.         lmode = SLIST;
  60.         break;
  61.  
  62.     case S_INH:
  63.         outab(op);
  64.         break;
  65.  
  66.     case S_BRA:
  67.         expr(&e1, 0);
  68.         v1 = e1.e_addr - dot->s_addr - 2;
  69.         if ((v1 < -128) || (v1 > 127))
  70.             aerr();
  71.         if (e1.e_base.e_ap != dot->s_area)
  72.             rerr();
  73.         outab(op);
  74.         outab(v1);
  75.         break;
  76.  
  77.     case S_TYP1:
  78.         t1 = addr(&e1);
  79.         espv = e1.e_addr;
  80.         espa = e1.e_base.e_ap;
  81.         if (t1 == S_A) {
  82.             outab(op+0x10);
  83.             break;
  84.         }
  85.         if (t1 == S_X) {
  86.             outab(op+0x20);
  87.             break;
  88.         }
  89.         if (t1 == S_DIR) {
  90.             outab(op);
  91.             outrb(&e1, 0);
  92.             break;
  93.         }
  94.         if (t1 == S_IX) {
  95.             outab(op+0x40);
  96.             break;
  97.         }
  98.         if (t1 == S_DIRX) {
  99.             outab(op+0x30);
  100.             outrb(&e1, 0);
  101.             break;
  102.         }
  103.         aerr();
  104.         break;
  105.  
  106.     case S_TYP2:
  107.         t1 = addr(&e1);
  108.         espv = e1.e_addr;
  109.         espa = e1.e_base.e_ap;
  110.         if (t1 == S_IMMED) {
  111.             if ((op == 0xA7) ||
  112.                 (op == 0xAC) ||
  113.                 (op == 0xAF))
  114.                 aerr();
  115.             outab(op);
  116.             outrb(&e1, 0);
  117.             break;
  118.         }
  119.         if (t1 == S_DIR) {
  120.             outab(op+0x10);
  121.             outrb(&e1, 0);
  122.             break;
  123.         }
  124.         if (t1 == S_EXT) {
  125.             outab(op+0x20);
  126.             outrw(&e1, 0);
  127.             break;
  128.         }
  129.         if (t1 == S_IX) {
  130.             outab(op+0x50);
  131.             break;
  132.         }
  133.         if (t1 == S_DIRX) {
  134.             outab(op+0x40);
  135.             outrb(&e1, 0);
  136.             break;
  137.         }
  138.         if (t1 == S_INDX) {
  139.             if (pass == 0) {
  140.                 dot->s_addr += 3;
  141.             } else
  142.             if (e1.e_flag ||
  143.                (espa && espa != dot->s_area)) {
  144.                 outab(op+0x30);
  145.                 outrw(&e1, 0);
  146.             } else
  147.             if (pass == 1) {
  148.                 if (e1.e_addr >= dot->s_addr)
  149.                     e1.e_addr -= fuzz;
  150.                 flag = 0;
  151.                 if (espv & ~0xFF)
  152.                     ++flag;
  153.                 if (setbit(flag)) {
  154.                     dot->s_addr += 3;
  155.                 } else {
  156.                     dot->s_addr += 2;
  157.                 }
  158.             } else {
  159.                 if (getbit()) {
  160.                     outab(op+0x30);
  161.                     outrw(&e1, 0);
  162.                 } else {
  163.                     outab(op+0x40);
  164.                     outrb(&e1, 0);
  165.                 }
  166.             }
  167.             break;
  168.         }
  169.         aerr();
  170.         break;
  171.  
  172.     case S_TYP3:
  173.     case S_TYP4:
  174.         t1 = addr(&e1);
  175.         espv = e1.e_addr;
  176.         if (t1 != S_IMMED)
  177.             aerr();
  178.         if (espv & ~0x07)
  179.             aerr();
  180.         e1.e_addr = op + 2*(espv&0x07);
  181.         comma();
  182.         t2 = addr(&e2);
  183.         if (t2 != S_DIR)
  184.             aerr();
  185.         espa = e2.e_base.e_ap;
  186.         if (espa && espa != sdp->s_area)
  187.             rerr();
  188.         if (type == S_TYP4) {
  189.             expr(&e3, 0);
  190.             v1 = e3.e_addr - dot->s_addr - 3;
  191.             if ((v1 < -128) || (v1 > 127))
  192.                 aerr();
  193.             if (e3.e_base.e_ap != dot->s_area)
  194.                 rerr();
  195.         }
  196.         outrb(&e1, 0);
  197.         outrb(&e2, 0);
  198.         if (type == S_TYP4)
  199.             outab(v1);
  200.         break;
  201.  
  202.     default:
  203.         err('o');
  204.     }
  205. }
  206.  
  207.  
  208. /*
  209.  * The next character must be a
  210.  * comma.
  211.  */
  212. VOID
  213. comma()
  214. {
  215.     if (getnb() != ',')
  216.         qerr();
  217. }
  218.  
  219. /*
  220.  * Machine specific initialization.
  221.  * Set up the bit table.
  222.  * Reset direct page.
  223.  */
  224. VOID
  225. minit()
  226. {
  227.     bp = bb;
  228.     bm = 1;
  229.     sdp->s_area = dot->s_area;
  230. }
  231.  
  232. /*
  233.  * Store `b' in the next slot of the bit table.
  234.  * If no room, force the longer form of the offset.
  235.  */
  236. int
  237. setbit(b)
  238. {
  239.     if (bp >= &bb[NB])
  240.         return(1);
  241.     if (b)
  242.         *bp |= bm;
  243.     bm <<= 1;
  244.     if (bm == 0) {
  245.         bm = 1;
  246.         ++bp;
  247.     }
  248.     return(b);
  249. }
  250.  
  251. /*
  252.  * Get the next bit from the bit table.
  253.  * If none left, return a `1'.
  254.  * This will force the longer form of the offset.
  255.  */
  256. int
  257. getbit()
  258. {
  259.     register f;
  260.  
  261.     if (bp >= &bb[NB])
  262.         return (1);
  263.     f = *bp & bm;
  264.     bm <<= 1;
  265.     if (bm == 0) {
  266.         bm = 1;
  267.         ++bp;
  268.     }
  269.     return (f);
  270. }
  271.